Context forms a tree where cancellation propagates from parent to all children. Every function that may block or do I/O should accept a ctx as its first parameter and respect its cancellation.
Pass context as the first parameter — never store it in a struct
Always call the cancel function returned by WithCancel/WithTimeout — even if the operation completes
Use context.WithValue only for request-scoped metadata (trace IDs, auth tokens) — not for optional parameters
Respect ctx.Done() in goroutines: select on it alongside work channels
Check ctx.Err() to distinguish context.Canceled from context.DeadlineExceeded